<template>
  <backContainer>
    <div class="flexBet">
      <div class="leftBox">
        <!-- 课程信息 -->
        <div class="infobox">
          <div style="width: 100%; display: flex" class="userbox">
            <div
              class="last_name"
              :style="{ 'background-color': $route.query.color }"
            >
              {{
                userInfo.studentName ? userInfo.studentName.slice(0, 1) : '--'
              }}
            </div>
            <div>
              <div class="name">{{ userInfo.studentName }}</div>
              <div class="stu_num">{{ userInfo.studentNum }}</div>
            </div>
          </div>

          <div class="major_name overTxt">
            <tooltip position="top" :text="userInfo.majorName" width="100%" />
          </div>
          <div class="major_name overTxt mt8">
            <tooltip
              position="top"
              :text="`行政班:${userInfo.className}`"
              width="100%"
            />
          </div>
          <div class="class_name overTxt">
            <tooltip
              position="top"
              :text="`授课班级:${userInfo.schedulingName}`"
              width="100%"
            />
          </div>
          <div class="ancestors_box">
            <div
              class="ancestors_name overTxt"
              :class="{ name_bold: index == userInfo.ancestorsName.length - 1 }"
              v-for="(item, index) in userInfo.ancestorsName"
              :key="index"
            >
              <tooltip position="top-start" :text="item" width="100%"/>
            </div>

            <div class="rela progress">
              <el-progress
                :percentage="userInfo.progressRate"
                color="#ffcd7c"
                define-back-color="#ebebeb"
                :stroke-width="4"
              ></el-progress>
            </div>
          </div>
        </div>
        <!-- 按钮组 -->
        <div class="btns_main">
          <div
            class="operation_btn"
            v-if="
              courseInfo.courseType != 3 &&
              userInfo.attendanceScorePercentage > 0
            "
            @click="
              routeTo('/studentGrade', { navActive: 'normal_attendance' })
            "
          >
            <img src="@/assets/images/group_icon/attendance.png" alt="加载失败"/>
            考勤打分
          </div>
          <div
            class="operation_btn"
            v-if="
              courseInfo.courseType != 3 &&
              userInfo.disciplineScorePercentage > 0
            "
            @click="showUsuallyAddDialog(3)"
          >
            <img src="@/assets/images/group_icon/discipline.png" alt="加载失败"/>
            纪律打分
          </div>
          <div
            class="operation_btn"
            v-if="$store.getters.schoolInfo.openUsualScore == 1 &&
              courseInfo.finishStatus != 1 &&
              userInfo.usualScorePercentage > 0"
            @click="showUsuallyAddDialog(1)"
          >
            <img
              src="@/assets/images/group_icon/daily_score_icon.png"
              alt="加载失败"
            />

            课堂表现打分
          </div>
          <div
            class="operation_btn"
            v-if="
              courseInfo.courseType != 3 && userInfo.otherScorePercentage > 0
            "
            @click="showUsuallyAddDialog(4)"
          >
            <img src="@/assets/images/group_icon/discipline.png" alt="加载失败"/>
            其他打分
          </div>

          <div
            class="operation_btn"
            @click="showResultAddDialog"
            v-if="$store.getters.curRole != 'assistant'"
          >
            <img
              src="@/assets/images/group_icon/studyResult.png"
              alt="加载失败"
            />
            查看学习成果
          </div>
          <div
            v-if="
              courseInfo.finishStatus != 1 &&
              $store.getters.curRole != 'assistant'
            "
            class="operation_btn"
            @click="finishCourse"
          >
            <img
              src="@/assets/images/group_icon/finish_course_icon.png"
              alt="加载失败"
            />
            完成剩余课程
          </div>
          <div
            v-if="
              !courseInfo.includeGroupExamNow &&
              courseInfo.finishStatus != 1 &&
              $store.getters.curRole != 'assistant'
            "
            class="operation_btn"
            @click="resetLearning"
          >
            <img
              src="@/assets/images/group_icon/reset_learn_icon.png"
              alt="加载失败"
            />
            重置学习进度
          </div>
          <div
            class="operation_btn"
            @click="resetGetout"
            v-if="$store.getters.curRole != 'assistant'"
          >
            <img src="@/assets/images/group_icon/out.png" alt="加载失败"/>
            重置进度并踢出
          </div>
          <div
            class="operation_btn"
            @click="resetPassword"
            v-if="$store.getters.curRole != 'assistant'"
          >
            <img
              src="@/assets/images/group_icon/reset_psd_icon.png"
              alt="加载失败"
            />
            重置学生密码
          </div>
        </div>
      </div>
      <el-dialog
        style="margin-top: 15vh"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="剩余未考核内容打分"
        :visible.sync="showFinishDialog"
        width="500px"
        append-to-body
        @close="cancel()"
      >
        <el-form
          ref="form"
          @submit.native.prevent
          :model="form"
          :rules="rules"
          label-width="80px"
        >
          <div class="sign">
            剩余所有未考核内容，以{{
              form.score ? form.score : '--'
            }}分（百分制）卷面分给分
          </div>
          <el-form-item label="分数" prop="score" placeholder="请输入分数">
            <el-input
              oninput="value=value.replace(/[^0-9]|^0+(?!$)/g,''); if(parseInt(value)>100) value='100';"
              v-model="form.score"
              placeholder="请输入分数"
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancel">取 消</el-button>
          <el-button type="primary" @click="submitForm">确 定</el-button>
        </div>
      </el-dialog>
      <!--  课堂表现分打分   -->
      <!-- 新增弹窗 -->
      <el-dialog
        :title="
          usualType == 1
            ? '课堂表现打分'
            : usualType == 3
            ? '纪律打分'
            : '其他打分'
        "
        :visible.sync="scoreOpen"
        width="600px"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        append-to-body
        @close="cancel()"
      >
        <el-form
          @submit.native.prevent
          ref="scoreForm"
          :model="scoreForm"
          :rules="scoreRules"
          label-width="120px"
        >
          <el-form-item label="课程名：" prop="teacherNum">
            {{ scoreForm.courseName }}
          </el-form-item>
          <el-form-item label="学生：" prop="name">
            {{ scoreForm.studentName }}({{ scoreForm.studentNum }})
          </el-form-item>

          <el-form-item
            :label="
              usualType == 1
                ? '课堂表现打分:'
                : usualType == 3
                ? '纪律打分:'
                : '其他打分:'
            "
            prop="sex"
          >
            {{ scoreForm.normalScore }}
          </el-form-item>
          <el-form-item label="本次打分：" prop="score">
            <div class="flexColCenter">
              <el-radio-group size="small" v-model="scoreType">
                <el-radio-button label="add">加</el-radio-button>
                <el-radio-button label="subtract">减</el-radio-button>
              </el-radio-group>
              <el-input-number
                :precision="1"
                v-model="scoreForm.score"
                controls-position="right"
                :min="0"
                :step="0.1"
              ></el-input-number>
              分 <span>（精确到十分位）</span>
            </div>
          </el-form-item>
          <el-form-item label="备注">
            <el-input
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 4 }"
              v-model="scoreForm.remark"
              placeholder="请输入备注"
              clearable
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button v-preventReClick @click="scoreOpen = false"
          >取 消
          </el-button
          >
          <el-button v-preventReClick type="primary" @click="scoreSubmitForm">
            打 分
          </el-button>
        </div>
      </el-dialog>
      <!-- 章节列表 -->
      <card
        :width="912"
        :top="0"
        :height="'calc(100vh - 68px - 18px - 60px + 24px)'"
        class="learningSituation"
      >
        <div class="title">模块学习情况</div>
        <div class="flex courseInfobox">
          <el-image
            :src="userInfo.coursePic"
            class="cover"
            fit="cover"
            :preview-src-list="[userInfo.coursePic]"
          ></el-image>
          <div class="info" style="width: 522px">
            <div
              style="align-items: center; justify-content: space-between"
              class="flex"
            >
              <div class="name overTxt">
                <tooltip
                  position="top"
                  :text="userInfo.courseName"
                  width="100%"
                />
              </div>
              <div class="time">
                共{{ userInfo.studyTime ? userInfo.studyTime : 0 }}课时
              </div>
            </div>
            <div :class="courseInfo.courseType != 3? 'table_content':'table_content cellLineHeight'">
              <!--  -->
              <el-table
                :data="scoreList"
                border
                ref="table"
                :span-method="arraySpanMethod"
                :cell-style="{ padding: '2px'}"
                :header-cell-style="{ height: '28px', padding: '0' }"
              >
                <el-table-column
                  prop="name"
                  label=""
                  align="center"
                  width="150"
                  fixed="left"
                >
                  <template slot-scope="scope">
                    <div class="">
                      {{ scope.row.name }}
                    </div>
                  </template>
                </el-table-column>
                <!-- 通用课程 -->
                <template v-if="courseInfo.courseType != 3">
                  <el-table-column
                    align="center"
                    prop="attendance"
                    label="考勤"
                  >
                    <template #header>
                      <span>
                        考勤
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            初始100分，在授课过程中根据考情异常情况扣分（排课时自定义异常情况扣分分数）
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="discipline"
                    label="纪律"
                  >
                    <template #header>
                      <span>
                        纪律
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            排课时自定义初始分，并在授课过程中进行分数加减（取0～100分计算得分）
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="usually"
                    label="课堂表现"
                    width="90"
                  >
                    <template #header>
                      <span>
                        课堂表现
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            排课时自定义初始分，并在授课过程中进行分数加减（取0～100分计算得分）
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="homework"
                    label="课后作业"
                    width="90"
                  >
                    <template #header>
                      <span>
                        课后作业
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            编辑课程时在内容中创建，学生学习该内容时完成，按照【课后作业权重明细】计算得分
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="process"
                    label="课后考核"
                    width="90"
                  >
                    <template #header>
                      <span>
                        课后考核
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            编辑课程时在内容中创建，学生学习该内容时进行考核，按照【任务考核权重明细】计算得分
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                  <el-table-column align="center" prop="other" label="其他">
                    <template #header>
                      <span>
                        其他
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            排课时自定义初始分，并在授课过程中进行分数加减（取0～100分计算得分）
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                </template>
                <!-- 工学一体课程 -->
                <template v-else>
                  <el-table-column label="过程性考核" align="center">
                    <el-table-column
                      align="center"
                      prop="usually"
                      label="课堂表现"
                      width="90"
                    >
                      <template #header>
                        <span>
                          课堂表现
                          <el-tooltip
                            class="item"
                            effect="dark"
                            :content="content"
                            placement="top"
                          >
                            <i style="cursor: pointer" class="el-icon-info"></i>
                            <div slot="content">
                              排课时自定义初始分，并在授课过程中进行分数加减（取0～100分计算得分）
                            </div>
                          </el-tooltip>
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      align="center"
                      prop="homework"
                      label="课后作业"
                      width="90"
                    >
                      <template #header>
                        <span>
                          课后作业
                          <el-tooltip
                            class="item"
                            effect="dark"
                            :content="content"
                            placement="top"
                          >
                            <i style="cursor: pointer" class="el-icon-info"></i>
                            <div slot="content">
                              在授课过程中进行打分（满分100，取平均分计算得分）
                            </div>
                          </el-tooltip>
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column
                      align="center"
                      prop="process"
                      label="任务考核"
                      width="90"
                    >
                      <template #header>
                        <span>
                          任务考核
                          <el-tooltip
                            class="item"
                            effect="dark"
                            :content="content"
                            placement="top"
                          >
                            <i style="cursor: pointer" class="el-icon-info"></i>
                            <div slot="content">
                              编辑课程时在内容中创建，学生学习该内容时进行考核，按照【任务考核权重明细】计算得分
                            </div>
                          </el-tooltip>
                        </span>
                      </template>
                    </el-table-column>
                  </el-table-column>
                  <el-table-column
                    align="center"
                    prop="exam"
                    label="终结性考核"
                    width="100"
                  >
                    <template #header>
                      <span>
                        终结性考核
                        <el-tooltip
                          class="item"
                          effect="dark"
                          :content="content"
                          placement="top"
                        >
                          <i style="cursor: pointer" class="el-icon-info"></i>
                          <div slot="content">
                            编辑课程时在期末考核中创建，学生期末考核中进行考核，按照【终结性考核权重明细】计算得分
                          </div>
                        </el-tooltip>
                      </span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
        <!-- 课程目录 -->
        <div class="chapterBox">
          <div class="topLine">
            <div class="course_title">课程目录</div>
            <div @click="handlechange" class="btns">
              <img
                v-if="!isClose"
                src="@/assets/images/courseAdd/expand.png"
                alt="加载失败"
              />
              <img
                v-else
                src="@/assets/images/courseAdd/shrink.png"
                alt="加载失败"
              />
              {{ !isClose ? '展开' : '收起' }}
            </div>
          </div>
          <div class="course_tree">
            <courseStudyTrees
              ref="course_trees_ref"
              :data="courseIndexTree"
              :courseInfo="courseInfo"
              :studentName="userInfo.studentName"
              :isLeader="userInfo.isLeader"
              :studentId="$route.query.studentId"
              @refresh="getStudentStudyIndexList"
            >
            </courseStudyTrees>
          </div>
        </div>
        <!-- 学习成果 -->
        <div class="studyResult">
          <el-dialog
            top="1vh"
            title="学习成果"
            width="1250px"
            :visible.sync="studyResultByTime_open"
          >
            <div class="flex">
              <div
                style="
                  max-height: calc(94vh - 60px - 200px + 40px);
                  width: 310px;
                  overflow: auto;
                "
              >
                <courseTrees
                  ref="resultTree"
                  type="detail"
                  :data="studyResultByTime_courseIndexTree"
                  @handleClick="handleClick"
                >
                </courseTrees>
              </div>

              <!-- 学习成果 -->
              <div style="width: 872px">
                <studyResultByTime
                  :className="userInfo.schedulingName"
                  formatter="byHour"
                  type="edit"
                  :courseId="userInfo.courseId"
                  ref="StudyResultByTime"
                  @close="studyResultByTime_open = false"
                ></studyResultByTime>
              </div>
            </div>
          </el-dialog>
        </div>
      </card>
    </div>
  </backContainer>
</template>

<script>
import { addusuallyPoints } from '@/api/tea_studentGrade/usual'
import StudyResultByTime from '@/components/studyResultByTime.vue'
import usuallyAddDialog from '@/components/usuallyAddDialog'
import {
  finishResidualIndex,
  kickOutStudent,
  resetLearningProgress,
  resetPassword,
  studentStudyIndexList,
  teaStudentInfo
} from '@/api/home'
import { formatTreeData } from './formatTreeDataToStudy'
import courseStudyTrees from './components/teacherCourseStudyTrees'
import courseTrees from '../tea_course/components/courseTrees'

export default {
  components: {
    usuallyAddDialog,
    courseStudyTrees,
    StudyResultByTime,
    courseTrees
  },
  props: {},
  data() {
    return {
      // 打分
      scoreOpen: false,
      usualType: 1,
      scoreType: 'add',
      scoreForm: {
        score: 0
      },
      scoreRules: {
        score: [
          { required: true, message: '分数不能为空', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              if (value === 0 || value === '0') {
                callback(new Error('分数不能为0'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ]
      },
      content: '',
      // 学习成果data
      studyResultByTime_open: false,
      studyResultByTime_courseIndexTree: null,
      //
      studentNormalScore: 0,
      scoreList: [],
      showFinishDialog: false,
      usuallyOpen: false,
      //openType:  1-->课堂表现    2-->课后作业   3-->课堂表现分
      openType: 3,
      usuallyTopInfo: null,
      isClose: true,
      //课程目录
      courseIndexTree: [],
      indexId: '',
      // 工作站
      userInfo: {},
      courseInfo: {},
      form: {
        score: ''
      },
      rules: {
        score: [
          {
            required: true,
            message: '请输入分数',
            trigger: 'blur'
          }
        ]
      },
      //用于成果的文件预览显示lable
      preview: {
        coursePath: '',
        courseName: '',
        studentId: '',
        studentName: ''
      }
    }
  },
  watch: {},
  methods: {
    routeTo(path, query) {
      this.$router.push({
        path: path,
        query: query
      })
    },
    transformIndexIdToId(nodes) {
      nodes.forEach((node) => {
        // 检查并重命名当前节点的indexId为id
        if (node.hasOwnProperty('indexId')) {
          node.id = node.indexId
          node.name = node.indexName
          node.submitType = node.examSubmitType
        }

        // 递归处理当前节点的children数组（如果存在）
        if (node.hasOwnProperty('children') && Array.isArray(node.children)) {
          this.transformIndexIdToId(node.children)
        }
      })
      return nodes
    },
    // 用于生成xx/xxx/xxxx
    async getPathToNode(nodes, targetId, pathAccumulator = []) {
      for (const node of nodes) {
        // 如果当前节点匹配目标ID，说明路径构建完成，返回累积的路径
        if (node.indexId === targetId) {
          return [...pathAccumulator, node.indexName] // 包含当前节点名称
        }

        // 递归查找子节点中的路径
        if (node.children && node.children.length > 0) {
          // 将当前节点的名称添加到路径中，然后递归查找
          const result = await this.getPathToNode(node.children, targetId, [
            ...pathAccumulator,
            node.indexName
          ])
          if (result) {
            return result // 找到路径，返回
          }
        }
      }

      return null // 未找到目标节点，返回null
    },
    // 点击节点
    handleClick(e) {
      this.getPathToNode(this.courseIndexTree, e.indexId).then(async(path) => {
        this.preview = {
          coursePath: path ? path.join('/') : '',
          courseName: this.userInfo.ancestorsName[0],
          studentId: this.userInfo.studentNum,
          studentName: this.userInfo.studentName
        }
        console.log(e)
        this.$refs.StudyResultByTime.getALLresult(e, '')
      })
    },
    // 查看学习学生优秀成果
    showResultAddDialog() {
      this.studyResultByTime_courseIndexTree = this.transformIndexIdToId(
        JSON.parse(JSON.stringify(this.courseIndexTree))
      )
      this.studyResultByTime_open = true
      this.$nextTick(() => {
        this.$refs.StudyResultByTime.getALLresult(
          { indexId: this.courseIndexTree[0].indexId },
          ''
        )
        this.$refs.resultTree.hightFirst()
      })
    },
    refreshList() {
      this.getTeaStudentInfo()
      this.getStudentStudyIndexList()
    },
    finishCourse() {
      if (this.userInfo.isLeader == 1) {
        this.$confirm(
          `小组组长不支持该操作，请先移除该生组长身份。`,
          '操作失败',
          {
            showCancelButton: false,
            confirmButtonText: '确定'
          }
        ).then(() => {
        })
        return
      }
      if (this.userInfo.studyStatus != 1) {
        this.$modal.msgWarning('该学生暂未开始学习，不能执行此操作')
        return
      }
      this.showFinishDialog = true
    },
    cancel() {
      this.resetForm('form')
      this.showFinishDialog = false
    },
    submitForm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid) {
          this.$confirm(`是否确认打分？`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(async() => {
              const loading = this.$loading({
                lock: true,
                text: '处理中...',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.3)'
              })
              let res
              try {
                res = await finishResidualIndex(
                  this.$route.query.courseStuId,
                  this.form.score
                )
              } catch (e) {
                loading.close()
              }
              const { code } = res
              if (code == 200) {
                loading.close()
                this.$modal.msgSuccess('处理成功')
                this.showFinishDialog = false
                this.getTeaStudentInfo()
                this.getStudentStudyIndexList()
              } else {
                loading.close()
              }
            })
            .catch(() => {
              this.$modal.msgInfo('已取消')
            })
        }
      })
    },
    scoreSubmitForm() {
      this.$refs['scoreForm'].validate(async(valid) => {
        if (valid) {
          try {
            this.loading = true
            let obj = JSON.parse(JSON.stringify(this.scoreForm))
            obj.score = this.scoreType == 'add' ? obj.score : -obj.score
            let res = await addusuallyPoints(obj)
            if (res.code == 200) {
              this.$modal.msgSuccess('打分成功!')
              this.scoreOpen = false
              this.getTeaStudentInfo()
            }
          } finally {
            this.loading = false
          }
        }
      })
    },
    showUsuallyAddDialog(openType) {
      if (this.userInfo.studyStatus != 1) {
        this.$modal.msgWarning('该学生暂未开始学习，不能执行此操作')
        return
      }
      this.scoreOpen = true
      this.usualType = openType
      this.scoreForm.type = openType
      this.scoreForm.courseName = this.userInfo.courseName
      this.scoreForm.score =
        this.scoreType == 'add' ? this.scoreForm.score : -this.scoreForm.score
      this.scoreForm.normalScore =
        this.usualType == 1
          ? this.userInfo.totalUsualScore
          : this.usualType == 3
            ? this.userInfo.totalDisciplineScore
            : this.userInfo.totalOtherScore
      this.scoreForm.studentId = this.$route.query.studentId
      this.scoreForm.studentName = this.userInfo.studentName
      this.scoreForm.studentNum = this.userInfo.studentNum
      this.scoreForm.courseName = this.userInfo.courseName
      this.scoreForm.teacherId = this.$store.getters.teacherId
      this.scoreForm.courseStuId = this.$route.query.courseStuId
      this.scoreForm.courseSchedulingId = this.$route.query.courseSchedulingId
    },
    // 展开关闭操作
    handlechange() {
      this.isClose = !this.isClose
      if (this.isClose) {
        this.$refs.course_trees_ref.expandAll()
      } else {
        this.$refs.course_trees_ref.collapseAll()
      }
    },
    // 获取学习进度课程目录
    async getStudentStudyIndexList() {
      let res = await studentStudyIndexList(this.$route.query.courseStuId)
      const { code, data } = res
      if (code == 200) {
        console.log(data.indexId, 11111)
        this.indexId = data.indexId
        this.courseIndexTree = formatTreeData(data.children)
      }
    },
    // 重置学习进度
    resetLearning() {
      this.$confirm(
        '学习进度及考核记录将清空，重新开始学习。确认重置吗？',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(async() => {
          let res = await resetLearningProgress(this.$route.query.courseStuId)
          if (res.code == 200) {
            this.$modal.msgSuccess('重置成功')
            this.$router.go(-1)
          }
        })
        .catch(() => {
          this.$modal.msgInfo('已取消')
        })
    },
    // 重置密码
    resetPassword() {
      this.$confirm('确认重置该学生的密码吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          let res = await resetPassword(this.$route.query.studentId)
          if (res.code == 200) {
            this.$modal.msgSuccess('重置成功')
            this.$router.go(-1)
          }
        })
        .catch(() => {
          this.$modal.msgInfo('已取消')
        })
    },
    // 重置进度并踢出
    resetGetout() {
      if (this.userInfo.isLeader == 1) {
        this.$confirm(`该学生为小组组长，无法踢出。`, '操作失败', {
          showCancelButton: false,
          confirmButtonText: '确定'
        }).then(() => {
        })
        return
      }

      this.$confirm(
        '该学生将被移出此课程，学习进度及考核记录清空，确认重置并踢出吗？',
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      )
        .then(async() => {
          let res = await kickOutStudent(this.$route.query.courseStuId)
          if (res.code == 200) {
            this.$modal.msgSuccess('踢出成功')
            this.$router.go(-1)
          }
        })
        .catch(() => {
          this.$modal.msgInfo('已取消')
        })
    },

    // 获取学生学习进度信息TODO获取接口
    async getTeaStudentInfo() {
      let res = await teaStudentInfo(this.$route.query.courseStuId)
      res.data.ancestorsName = res.data.ancestorsName
        ? res.data.ancestorsName.split('/')
        : ['暂无学习中记录']
      this.userInfo = res.data
      let arr = [
        {
          name: '分数配比',
          attendance:
            res.data.attendanceScorePercentage ||
            res.data.attendanceScorePercentage == '0%'
              ? res.data.attendanceScorePercentage + '%'
              : '0%',
          discipline:
            res.data.disciplineScorePercentage ||
            res.data.disciplineScorePercentage == '0%'
              ? res.data.disciplineScorePercentage + '%'
              : '0%',
          usually:
            res.data.usualScorePercentage ||
            res.data.usualScorePercentage == '0%'
              ? res.data.usualScorePercentage + '%'
              : '0%',
          homework:
            res.data.homeworkScorePercentage ||
            res.data.homeworkScorePercentage == '0%'
              ? res.data.homeworkScorePercentage + '%'
              : '0%',
          process:
            res.data.processScorePercentage ||
            res.data.processScorePercentage == '0%'
              ? res.data.processScorePercentage + '%'
              : '0%',
          other:
            res.data.otherScorePercentage ||
            res.data.otherScorePercentage == '0%'
              ? res.data.otherScorePercentage + '%'
              : '0%',
          exam:
            res.data.examScorePercentage || res.data.examScorePercentage == '0%'
              ? res.data.examScorePercentage + '%'
              : '0%'
        },
        {
          name: '得分',
          attendance:
            res.data.totalAttendanceScore || res.data.totalAttendanceScore == 0
              ? res.data.totalAttendanceScore
              : '--',
          discipline:
            res.data.totalDisciplineScore || res.data.totalDisciplineScore == 0
              ? res.data.totalDisciplineScore
              : '--',
          usually:
            res.data.totalUsualScore || res.data.totalUsualScore == 0
              ? res.data.totalUsualScore
              : '--',
          homework:
            res.data.totalHomeworkScore || res.data.totalHomeworkScore == 0
              ? res.data.totalHomeworkScore
              : '--',
          process:
            res.data.totalProcessScore || res.data.totalProcessScore == 0
              ? res.data.totalProcessScore
              : '--',
          other:
            res.data.totalOtherScore || res.data.totalOtherScore == 0
              ? res.data.totalOtherScore
              : '--',
          exam:
            res.data.totalExamScore || res.data.totalExamScore == 0
              ? res.data.totalExamScore
              : '--'
        },
        {
          name: '得分(折算为百分制)',
          attendance:
            res.data.attendanceScore || res.data.attendanceScore == 0
              ? res.data.attendanceScore
              : '--',
          discipline:
            res.data.disciplineScore || res.data.disciplineScore == 0
              ? res.data.disciplineScore
              : '--',
          usually:
            res.data.usualScore || res.data.usualScore == 0
              ? res.data.usualScore
              : '--',
          homework:
            res.data.homeworkScore || res.data.homeworkScore == 0
              ? res.data.homeworkScore
              : '--',
          process:
            res.data.processScore || res.data.processScore == 0
              ? res.data.processScore
              : '--',
          other:
            res.data.otherScore || res.data.otherScore == 0
              ? res.data.otherScore
              : '--',
          exam:
            res.data.examScore || res.data.examScore == 0
              ? res.data.examScore
              : '--'
        },
        {
          name: '课程得分',
          attendance:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          discipline:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          usually:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          homework:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          process:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          other:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--',
          exam:
            res.data.totalScore || res.data.totalScore == 0
              ? res.data.totalScore
              : '--'
        }
      ]
      this.studentNormalScore = res.data.totalUsualScore
        ? res.data.totalUsualScore
        : 0
      this.scoreList = arr
    },
    arraySpanMethod({ rowIndex, columnIndex }) {
      let index = this.courseInfo.courseType == 3 ? 4 : 6
      if (rowIndex === 3) {
        if (columnIndex === 0) {
          // 第一个列不合并
          return [1, 1]
        } else if (columnIndex >= 1 && columnIndex <= index) {
          // 第二列到第六列合并为一列
          if (columnIndex === index) {
            return [1, index] // 从第二列开始合并5列
          } else {
            return [0, 0] // 隐藏第三到第六列
          }
        }
      }

      // 其他行保持默认行为
      return [1, 1]
    }
  },
  created() {
    this.courseInfo = JSON.parse(localStorage.getItem('COURSE_INFO'))
  },
  mounted() {
    this.getTeaStudentInfo()
    this.getStudentStudyIndexList()
  }
}
</script>
<style scoped lang="scss">
.studyResult {
  // ::v-deep {
  //   .el-dialog__header {
  //     display: none;
  //   }
  ::v-deep .el-dialog__body {
    padding: 20px 26px !important;
  }
}

.currentName {
  font-size: 18px;
  font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
  font-weight: 600;
  color: #333333;
  line-height: 18px;
}

.infobox {
  width: 272px;
  // min-height: 346px;
  background: white;
  border-radius: 16px;
  padding: 24px 0 25px 0;
  box-sizing: border-box;
  .userbox {
    box-sizing: border-box;
    padding: 0 20px;
  }
  .last_name {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
    font-family: PingFangSC, PingFang SC, sans-serif;
    font-weight: 600;
    color: #ffffff;
  }

  .name {
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    text-align: center;
    font-size: 18px;
    line-height: 25px;
    font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
    font-weight: 600;
    color: #333333;
  }

  .stu_num {
    padding: 0 10px;
    box-sizing: border-box;
    font-size: 14px;
    font-family: PingFangSC, PingFang SC, sans-serif;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
  }
  .mt8 {
    margin-top: 8px !important;
  }
  .major_name {
    box-sizing: border-box;
    padding: 0 20px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC, sans-serif;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
    margin-top: 10px;
  }

  .class_name {
    padding: 0 20px;
    width: 100%;
    box-sizing: border-box;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC, sans-serif;
    font-weight: 400;
    color: #999999;
    line-height: 20px;
    margin-top: 8px;
    padding-bottom: 20px;
    border-bottom: 1px solid #edeff0;
  }

  .name_bold {
    color: #333333 !important;
    font-weight: bold !important;
  }
  .ancestors_box {
    padding: 20px 24px 0 24px;
    box-sizing: border-box;

    .ancestors_name {
      margin-bottom: 8px;
      width: 100%;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC, sans-serif;
      font-weight: 400;
      color: #666666;
    }

    .progress {
      width: 234px;
    }

    .day {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC, sans-serif;
      font-weight: 400;
      color: #333333;
      line-height: 17px;
    }

    .rate {
      font-size: 10px;
      font-family: PingFangSC-Regular, PingFang SC, sans-serif;
      font-weight: 400;
      color: #999999;
      line-height: 14px;
    }
  }
}

.operation_btn {
  width: 272px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC, sans-serif;
  font-weight: 400;
  color: #666666;
  background: white;
  margin-top: 10px;

  img {
    margin: 0 10px 0 80px;
    width: 16px;
    height: 16px;
  }
}

.learningSituation {
  overflow: auto;

  .title {
    margin: 24px 0 0 24px;
    font-size: 18px;
    font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
    font-weight: 600;
    color: #333333;
    line-height: 25px;
  }

  .courseInfobox {
    margin: 10px 0 19px 24px;
    align-items: center;

    .cover {
      box-sizing: border-box;
      border: 1px solid #e6e6e6;
      border-radius: 16px;
      width: 302px;
      height: 190px;
    }

    .info {
      margin-left: 20px;

      .name {
        width: 400px;
        font-size: 18px;
        font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
        font-weight: 600;
        color: #333333;
        line-height: 25px;
      }

      .time {
        margin-left: 14px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC, sans-serif;
        font-weight: 400;
        color: #ef7d00;
      }
    }
  }

  .chapterBox {
    padding: 0px 40px 0 24px;

    .topLine {
      width: 100%;
      display: flex;
      align-items: center;

      .course_title {
        font-size: 18px;
        font-family: PingFangSC-Semibold, PingFang SC, sans-serif;
        font-weight: 600;
        color: #333333;
      }

      .btns {
        display: flex;
        align-items: center;
        cursor: pointer;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC, sans-serif;
        font-weight: 400;
        color: #666666;
        margin-left: 10px;

        img {
          margin: 0 4px 0 0;
          width: 16px;
          height: 16px;
        }
      }
    }

    .course_tree {
      width: 100%;
      height: calc(100vh - 188px);
      overflow: auto;
    }

    .chapter {
      height: 48px;
      align-items: center;
      border-bottom: 1px solid #edeff0;

      .name {
        box-sizing: border-box;
        width: 600px;
        margin-left: 15px;
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC, sans-serif;
        font-weight: 400;
        color: #666666;
        line-height: 22px;
      }

      .status {
        align-items: center;

        .makeUp {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC, sans-serif;
          font-weight: 400;
          color: #999999;
          line-height: 20px;

          span {
            color: #e95756;
          }
        }

        .icon1 {
          margin-left: 24px;
          border-radius: 50%;
          width: 8px;
          height: 8px;
          box-sizing: border-box;
          border: 2px solid #28b28b;
        }

        .icon2 {
          margin-left: 24px;
          border-radius: 50%;
          box-sizing: border-box;
          width: 8px;
          height: 8px;
          background: #28b28b;
          border: 2px solid #28b28b;
        }

        .icon-1 {
          margin-left: 24px;
          border-radius: 50%;
          box-sizing: border-box;
          width: 8px;
          height: 8px;
          background: #ffffff;
          border: 2px solid #e95756;
        }

        .icon0 {
          margin-left: 24px;
          border-radius: 50%;
          width: 8px;
          height: 8px;
          box-sizing: border-box;
          background: #ffffff;
          border: 2px solid #2cacff;
        }

        .label {
          margin-left: 16px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC, sans-serif;
          font-weight: 400;
          color: #666666;
          line-height: 20px;
        }
      }
    }
  }
}

.learningSituation::-webkit-scrollbar {
  display: none;
}

.btns {
  cursor: pointer;
  user-select: none;
}

.table_content {
  margin-top: 6px;
  ::v-deep .el-table .cell{
    line-height: 26px !important;
    padding: 0 !important;
  }

}
.table_content.cellLineHeight{
  ::v-deep .el-table .cell{
    line-height: 20px !important;
    padding: 0 !important;
  }
}
.sign {
  color: orange;
  margin: 0 0 10px 30px;
}

.leftBox {
  height: calc(100vh - 125px);
  display: flex;
  flex-direction: column;
}

.btns_main {
  width: 100%;
  flex: 1;
  overflow-y: auto;
}

.btns_main::-webkit-scrollbar {
  display: none;
}
</style>
